package com.wcpdoc.exam.core.dao.impl;

import com.wcpdoc.core.dao.impl.RBaseDaoImpl;
import com.wcpdoc.core.entity.PageIn;
import com.wcpdoc.core.entity.PageOut;
import com.wcpdoc.exam.core.dao.MyMockQuestionDao;
import com.wcpdoc.exam.core.dao.MyQuestionDao;
import com.wcpdoc.exam.core.entity.MyMockQuestion;
import com.wcpdoc.exam.core.entity.MyQuestion;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 我的试题数据访问层实现
 * <p>
 * v1.0 zhanghc 2017-06-19 16:28:29
 */
@Repository
public class MyMockQuestionDaoImpl extends RBaseDaoImpl<MyMockQuestion> implements MyMockQuestionDao {

    @Override
    public PageOut getListpage(PageIn pageIn) {
        return null;
    }

    @Override
    public List<Map<String, Object>> getListUser(String id) {
        return null;
    }

    @Override
    public List<MyMockQuestion> getList(Integer examId, Integer userId) {
        String sql = "SELECT * FROM EXM_MY_MOCK_QUESTION WHERE EXAM_ID = :EXAM_ID AND USER_ID = :USER_ID ORDER BY NO";
        return getList(sql, new Object[]{examId, userId}, MyMockQuestion.class);
    }

    @Override
    public MyMockQuestion getMyQuestion(Integer examId, Integer userId, Integer questionId) {
        String sql = "SELECT * FROM EXM_MY_MOCK_QUESTION WHERE EXAM_ID = :EXAM_ID AND USER_ID = :USER_ID AND QUESTION_ID = :QUESTION_ID";
        return getEntity(sql, new Object[]{examId, userId, questionId});
    }

    @Override
    public void clear(Integer examId) {
        String sql = "DELETE FROM EXM_MY_MOCK_QUESTION WHERE EXAM_ID = :EXAM_ID";
        update(sql, new Object[]{examId});
    }

    @Override
    public void clearMyMockExamQuestion(Integer examId, Integer userId) {
        String sql = "DELETE FROM EXM_MY_MOCK_QUESTION WHERE EXAM_ID = :EXAM_ID AND USER_ID=:USER_ID";
        update(sql, new Object[]{examId, userId});
    }


    @Override
    public void clearAnswer(Integer examId, Integer userId) {
        String sql = "UPDATE EXM_MY_MOCK_QUESTION " +
                "SET USER_SCORE = NULL ," +
                " USER_ANSWER =NULL," +
                "ANSWER_TIME=NULL " +
                "WHERE EXAM_ID = :EXAM_ID AND USER_ID = :USER_ID AND TYPE=2";
        update(sql, new Object[]{examId, userId});
    }

    @Override
    public void updateByRandom(Integer myMockQuestionId, Integer questionId, Integer examId, Integer userId) {
        String sql = "UPDATE EXM_MY_MOCK_QUESTION " +
                "SET QUESTION_ID = :QUESTION_ID " +
                "WHERE EXAM_ID = :EXAM_ID AND USER_ID = :USER_ID AND ID=:ID";
        update(sql, new Object[]{questionId, examId, userId, myMockQuestionId});
    }


}
